//
//  VisitorViewController.m
//  weibo
//
//  Created by qiuming on 15/12/22.
//  Copyright © 2015年 qiuming. All rights reserved.
//

#import "VisitorViewController.h"
#import "VisitorView.h"
#import "Extensions.h"
#import "OAuthViewController.h"

@interface VisitorViewController()

@property (strong, nonatomic) VisitorView *visitorView;
// 是否登录
@property (assign, nonatomic) BOOL userLogon;

@end

@implementation VisitorViewController

- (void)loadView {
    self.userLogon = [UserAccountViewModel sharedUserAccount].isLogin;
    self.userLogon ? [super loadView] : [self setupVisitorView];
}

- (void)setupVisitorView {
    
    self.visitorView = [[VisitorView alloc]init];
    self.view = self.visitorView;
}

- (void)setupUIWithImageName:(NSString *)imageName message:(NSString *)message loginSuccessBlock:(void(^)())loginSuccessBlock {
    
    if (!self.userLogon) {
        // 添加导航栏
        self.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonWithTitle:@"注册" imageName:nil target:self action:@selector(registerBtnClick)];
        
        self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonWithTitle:@"登录" imageName:nil target:self action:@selector(loginBtnClick)];
        
        // 设置访客视图
        [self.visitorView visitorInfoWithImageName:imageName message:message];
        
        // 添加点击方法
        [self.visitorView.registerBtn addTarget:self action:@selector(registerBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.visitorView.loginBtn addTarget:self action:@selector(loginBtnClick) forControlEvents:UIControlEventTouchUpInside];
    } else if (loginSuccessBlock != nil) {
        loginSuccessBlock();
    }
}

- (void)registerBtnClick {
    NSLog(@"注册");
}

- (void)loginBtnClick {
    
    OAuthViewController *oauth = [[OAuthViewController alloc]init];
    
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:oauth];
    
    [self presentViewController:nav animated:YES completion:nil];
    
}
@end














